{extend name="base" /}
{block name="main"}
<style type="text/css">
    .layui-form-checkbox {
        height: 22px;
        line-height: 20px;
        margin-right: 0px;
        padding-right: 20px;
    }

    .layui-form-checkbox i {
        right: 3px;
        width: 20px;
        font-size: 16px;
        top: 2px;
    }
</style>
<div class="fly-panel fly-panel-user">
    <div class="tpt—admin">
        <div class="tpt—btn" style="float: left;margin: 0 20px 0 0">
            <a href="{:url('member/add')}"><i class="layui-icon">&#xe61f;</i> 添加会员</a>
        </div>

        <div style="float: left;">
            <form class="layui-form" action="" method="get">
                <input placeholder="输入关键字" name="ks" value="<?php echo input('ks');?>" type="text" class="layui-input"
                       style="float: left;margin-right: 10px;width: 240px;">
                <button class="layui-btn" style="float: left;" value="查询" type="submit">查询</button>
            </form>
        </div>

        <form class="layui-form">
            <table width="100%">
                <tr>
                    <th width="5%" align="center"><input type="checkbox" name="checkAll" lay-filter="checkAll"></th>
                    <th width="5%" align="center">ID</th>
                    <th width="10%" align="center">昵称</th>
                    <th width="10%" align="center">积分</th>
                    <th width="10%" align="center">邮箱</th>
                    <th width="10%" align="center">时间</th>
                    <th width="10%" align="center">登录验证</th>
                    <th width="10%" align="center">实名认证</th>
                    <th width="10%" align="center">操作验证</th>
                    <th width="10%" align="center">基本操作</th>
                </tr>
                {volist name="tptc" id="vo"}
                <tr>
                    <td align="center"><input type="checkbox" name="ids[{$vo.userid}]" lay-filter="checkOne"
                                              value="{$vo.userid}"></td>
                    <td align="center">{$vo.userid}</td>
                    <td align="center">{$vo.username}</td>
                    <td align="center">{$vo.point}</td>

                    <td align="center">{if condition="$vo['usermail'] neq ''"}{$vo.usermail}{else /}邮箱未填{/if}</td>
                    <td align="center">{$vo.usertime|date="Y-m-d",###}</td>
                    <td align="center">{$vo.validate}</td>
                    <td align="center">
                        <a change="{$vo.userid}" onclick="changeusereal(this);" {if condition="$vo['usereal'] eq 1"
                           }class="layui-unselect layui-form-switch layui-form-onswitch" {else /}class="layui-unselect
                        layui-form-switch"{/if}>
                        <em>认证</em><i></i>
                        </a>
                    </td>
                    <td align="center">
                        <a change="{$vo.userid}" onclick="changestatus(this);" {if condition="$vo['status'] eq 1"
                           }class="layui-unselect layui-form-switch layui-form-onswitch" {else /}class="layui-unselect
                        layui-form-switch"{/if}>
                        <em>验证</em><i></i>
                        </a>
                    </td>
                    <td align="center">
                        <a class="layui-btn layui-btn-xs layui-btn-warm"
                           href="{:url('member/edit',array('id'=>$vo['userid']))}">修改</a> <a
                            class="layui-btn layui-btn-xs layui-btn-danger del_btn" member-id="{$vo.userid}" title="删除"
                            nickname="{$vo.username}">删除</a>
                    </td>
                </tr>
                {/volist}
            </table>
            <div class="layui-form-item">
                <div style="margin-top: 20px;float: left;">
                    <button class="layui-btn" lay-submit lay-filter="delete">删除选中</button>
                </div>
                <div class="pages" style="float: right;">{$tptc->render()}</div>
            </div>
        </form>
        <script>
            function changestatus(o) {
                var change = $(o).attr("change");
                $.ajax({
                    type: "post",
                    dataType: "json",
                    data: {change: change},
                    url: "{:url('member/changestatus')}",
                    success: function (data) {
                        if (data == 1) {
                            $(o).attr("class", "layui-unselect layui-form-switch");
                        } else {
                            $(o).attr("class", "layui-unselect layui-form-switch layui-form-onswitch");
                        }
                    }
                });
            }

            function changeusereal(o) {
                var change = $(o).attr("change");
                $.ajax({
                    type: "post",
                    dataType: "json",
                    data: {change: change},
                    url: "{:url('member/changeusereal')}",
                    success: function (data) {
                        if (data == 1) {
                            $(o).attr("class", "layui-unselect layui-form-switch");
                        } else {
                            $(o).attr("class", "layui-unselect layui-form-switch layui-form-onswitch");
                        }
                    }
                });
            }
        </script>
        <script>
            layui.use('form', function () {
                var form = layui.form,
                    jq = layui.jquery;

                jq('.del_btn').click(function () {
                    var name = jq(this).attr('nickname');
                    var id = jq(this).attr('member-id');
                    layer.confirm('确定删除【' + name + '】?', function (index) {
                        loading = layer.load(2, {
                            shade: [0.2, '#000']
                        });
                        jq.post('{:url("member/dels")}', {'id': id}, function (data) {
                            if (data.code == 200) {
                                layer.close(loading);
                                layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                                    location.reload();
                                });
                            } else {
                                layer.close(loading);
                                layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
                            }
                        });
                    });
                });

                form.on('checkbox(checkAll)', function (data) {
                    if (data.elem.checked) {
                        jq("input[type='checkbox']").prop('checked', true);
                    } else {
                        jq("input[type='checkbox']").prop('checked', false);
                    }
                    form.render('checkbox');
                });

                form.on('checkbox(checkOne)', function (data) {
                    var is_check = true;
                    if (data.elem.checked) {
                        jq("input[lay-filter='checkOne']").each(function () {
                            if (!jq(this).prop('checked')) {
                                is_check = false;
                            }
                        });
                        if (is_check) {
                            jq("input[lay-filter='checkAll']").prop('checked', true);
                        }
                    } else {
                        jq("input[lay-filter='checkAll']").prop('checked', false);
                    }
                    form.render('checkbox');
                });

                form.on('submit(delete)', function (data) {
                    var is_check = false;
                    jq("input[lay-filter='checkOne']").each(function () {
                        if (jq(this).prop('checked')) {
                            is_check = true;
                        }
                    });
                    if (!is_check) {
                        layer.msg('请选择数据', {icon: 2, anim: 6, time: 1000});
                        return false;
                    }
                    layer.confirm('确定批量删除?', function (index) {
                        loading = layer.load(2, {
                            shade: [0.2, '#000']
                        });
                        var param = data.field;
                        jq.post('{:url("member/delss")}', param, function (data) {
                            if (data.code == 200) {
                                layer.close(loading);
                                layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                                    location.reload();
                                });
                            } else {
                                layer.close(loading);
                                layer.msg(data.msg, {icon: 2, anim: 6, time: 1000});
                            }
                        });
                    });
                    return false;
                });

            })
        </script>
    </div>
</div>

{/block}